<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.Constants"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="com.hll.model.Book"%>
<%@ page import="com.hll.util.StringUtil"%>

<%
    String status = (String) request.getAttribute("status");
    int i = 0;
    List<Book> books = (List<Book>) request.getAttribute("books");
%>

<div class="table">

  <div class="header">
    <ul>
      <li class="index">编号</li>
      <li class="book-info">书籍</li>
      <%
          if (status.equals("borrow")) {
      %>
      <li class="book-sharer">共享者</li>
      <%
          } else {
      %>
      <li class="book-status">状态</li>
      <li class="book-operator">操作</li>
      <%
          }
      %>
      <li class="book-history">借阅历史</li>
    </ul>
  </div>

  <div class="content">
  <%
      for (Book book : books) {
          i++;
  %>
    <div>
      <ul>
        <li class="index"><%=i%></li>
        <li class="book-info">
          <img class="book-img" src="<%=request.getContextPath() + book.getPicture()%>"/> 
          <label class="book-title" title="<%=book.getName()%>"><%=StringUtil.htmlEncode(book.getName())%></label>
          <label class="book-author" title="<%=book.getAuthor()%>"><%=StringUtil.htmlEncode(book.getAuthor())%></label>
        </li>
  
      <%
          if ("borrow".equals(status)) {
      %>
        <li class="book-sharer">
          <img src="<%=request.getContextPath()%>/static/images/ICN_Holder_Blue_30x30.png"/>
          <label class="holder-name"> <%=StringUtil.htmlEncode(book.getOwnerName())%></label>
        </li>
      <%
          } else {
      %>
        <li class="book-status">
          <img src="<%=request.getContextPath()%>/static/images/ICN_Holder_Blue_30x30.png"/>
          <label class="holder-name"> <%=StringUtil.htmlEncode(book.getCurrentOwnerName())%></label> 
          <%
              if (book.getCurrentOwnerId() == book.getOwnerId()) {
          %>
            <label class="status-dec">[未借出]</label>
          <%
              } else {
          %> 
            <label class="status-dec">[已借出]</label> 
          <%
              }
          %>
        </li>
        <li class="book-operator">
          <div class="cell">
          <%
              if (book.getCurrentOwnerId() == book.getOwnerId()) {
          %>
            <a class="update-button" href="<%=request.getContextPath()%>/editBook.action?id=<%=book.getId()%>">更新</a>
            <div class="update-button" onclick="showDeleteBookWin(<%=book.getId()%>)">删除</div>
          <%
              } else {
          %>
            <a class="update-button" href="<%=request.getContextPath()%>/editBook.action?id=<%=book.getId()%>">更新</a>
          <%
              }
          %>
          </div>
        </li>
      <%
          }
      %>
  
        <li class="book-history">
          <div class="short-desc">
            2019年11月4 &nbsp;:&nbsp;借给zack.liu <br />
            2019年11月4 &nbsp;:&nbsp;借给billy.he <br /> 
            2019年11月4 &nbsp;:&nbsp;录入系统 <br />
          </div> 
          <img class="read-more" src="<%=request.getContextPath()%>/static/images/ICN_ReadMore_30x10.png" />
        </li>
      </ul>
    </div>
  <%
  } // End of books interator
  %>
  </div>
</div>